﻿@model IEnumerable<DeviceDefectManager_WCG.Models.Defect>
@{
    ViewBag.Title = "任务缺陷管理系统";
}
<h2>主页</h2>
<p>
    @Html.ActionLink("添加缺陷", "Create")
</p>
<form action="/" method="get" class="form-inline text-center" style="margin:10px">
    所属设备：@Html.DropDownList("DeviceID", null, new { @class = "form-control" })
    缺陷内容：<input type="text" name="Content" class="form-control" placeholder="请输入关键字" />
   
    缺陷状态：
    @Html.RadioButton("DefectState", 1, new { @class = "radio-inline" }) 未处理
    @Html.RadioButton("DefectState", 2, new { @class = "radio-inline" }) 已处理
    @Html.RadioButton("DefectState", 0, true, new { @class = "radio-inline" }) 全部
    <input type="submit" value="查询" class="btn btn-primary" />
</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Device.DeviceName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectTypeStr)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DefectStateStr)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DealTime)
        </th>
        <th class="text-center">操作</th>
    </tr>

    @foreach (var item in Model)
    {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Device.DeviceName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DefectTypeStr)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Content)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.AddTime)
    <td>
        @Html.DisplayFor(modelItem => item.DefectStateStr)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DealTime)
    </td>
    <td class="text-right">
        @*@Html.ActionLink("处理缺陷", "Edit", new { id = item.DefectID })*@
        @{
            if (item.DefectState == 1)
            {
                <a href="#" edit="@item.DefectID" class="btn btn-primary">处理缺陷</a>
            }
        }
        <a href="#" data-del="@item.DefectID" class="btn btn-danger ">删除</a>
    </td>
</tr>
    }

</table>
@section scripts{
    <script type="text/javascript">
        $(function () {
            $("a[data-del]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-del");
                if (!confirm("确定要删除吗？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Delete")", { id: id }, function (res) {
                    if (res) {
                        $this.closest("tr").remove();
                        alert("删除成功");
                    }
                })
            })
        })
             $("a[edit]").click(function () {
                 var id = $(this).attr("edit");
                if (!confirm("确定处理缺陷？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Edit")", { id: id }, function (res) {
                    if (res) {
                        location.reload();//刷新整个页面
                        alert("缺陷处理成功");
                    }

                })
            })
    </script>


}
